package com.jwell.panprovider.ui.adapter

import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.jwell.panprovider.R
import com.jwell.panprovider.entity.AppContratcListDto
import com.jwell.panprovider.ui.activity.ElectronicPoundInfoActivity
import com.jwell.panprovider.ui.activity.ProviderRegisterActivity
import kotlinx.android.synthetic.main.item_transport_plane_info_jh_layout.view.*

/**
 * Created by 76577 on 2018/4/22.
 * 供应详情-计划信息-合同号适配器
 */
class TransportInfoContractAdapter constructor(list: List<AppContratcListDto>) : RecyclerView.Adapter<TransportInfoContractAdapter.ViewHolder>() {
    private var list = list
    private var planType = 1//计划类型 1、按合同号 2、按品名 = ['1', '2'],
    private var booleShowRegister = false
    private var listener: RegisterOnclickListener? = null
    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_transport_plane_info_jh_layout, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        with(holder.itemView) {
            text_register.setOnClickListener {
                listener?.onClick(position)
            }
            text_contractNum.text = "执行单行号:" + (list[position].mtrlOrderNo ?: "")
            text_chang_jia.text = "厂家:" + (list[position].manufactureR_DETAIL ?: "")
            text_chang_di.text = "产地:" + (list[position].producinG_SIMPLE ?: "")
            text_appoint_num.text = list[position].appointCarCount.toString() + "车"
            text_have_provide_num.text = list[position].supplyCar.toString() + "车/" + list[position].supplyTon + "吨"
            text_goodsName.text = list[position].mtrlDescr ?: ""
            when (planType) {
                1 -> {
                    ll_appoint.visibility = View.VISIBLE
                }
                2 -> {
                    ll_appoint.visibility = View.GONE
                }
            }
            if (list[position].isKegogny) {//可以供应
                text_register.visibility = View.VISIBLE
                text_register.text = "预登记"
                text_register.setBackgroundResource(R.drawable.bg_green_15dp)
                text_register.setTextColor(holder.itemView.context.resources.getColor(R.color.white))
                text_register.isClickable = true
            } else {//不可以供应
                text_register.visibility = View.VISIBLE
                text_register.text = "登记名额\n已用完"
                text_register.setTextColor(holder.itemView.context.resources.getColor(R.color.c999999))
                text_register.isClickable = false
            }
            when (booleShowRegister) {
                true -> {
                    text_register.visibility = View.VISIBLE
                }
                false -> {
                    text_register.visibility = View.GONE
                }
            }
        }
    }

    fun setPlaneType(planeType: Int) {
        this.planType = planeType
        notifyDataSetChanged()
    }

    fun setBooleShowRegister(booleShowRegister: Boolean) {
        this.booleShowRegister = booleShowRegister
        notifyDataSetChanged()
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)

    interface RegisterOnclickListener {
        fun onClick(position: Int)
    }

    fun setRegisterOnclickListener(listener: RegisterOnclickListener) {
        this.listener = listener
    }

}